﻿using System;
using System.Text;
using System.IO;

namespace HRSystem.Utility
{
    public static class FileLog
    {
        private static string LogFileName = String.Empty;
        private static string ErrorFileName = String.Empty;

        public static void SetLogFile(string filename)
        {
            LogFileName = filename;
        }

        public static void SetErrorFile(string filename)
        {
            ErrorFileName = filename;
        }

        public static void LogError(Exception e)
        {
            WriteFile(ErrorFileName,String.Format("Source={0},Description={1},Data={2}",DateTime.Now.ToString(),e.Source,e.Message,e.Data.ToString()));
        }

        public static void Log(string str)
        {
            WriteFile(LogFileName,str);
        }

        public static void WriteFile(string filepath,string str)
        {
            str = DateTime.Now.ToString() + " " + str;
            FileStream fs = new FileStream(filepath,FileMode.Append);
            StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.Default);
            sw.Flush();
            sw.WriteLine(str);

            sw.Close();
            fs.Close();
        }
    }
}